<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改参数')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-db-add" >
        <input  name="tableName" id="tableName" type="hidden" th:value="${table_name}">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">字段名称：</label>
            <div class="col-sm-8">
                <input  name="name"  class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">字段类型：</label>
            <div class="col-sm-8" >
                <select id="type" name="type"  class="area form-control m-b"  onchange="selectOnchange(this)">
                    <option value="">选择类型</option>
                    <option value="VARCHAR2">VARCHAR2</option>
                    <option value="NUMBER">NUMBER</option>
                    <option value="DATE">DATE</option>
                    <option value="CHAR">CHAR</option>
                </select>
            </div>
        </div>
        <div class="form-group" id="length">
            <label class="col-sm-3 control-label is-required">字段长度：</label>
            <div class="col-sm-8">
                <input  name="length"  onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group" id="isNullShow">
            <label class="col-sm-3 control-label is-required">是否为空：</label>
            <div class="col-sm-8" >
                <select  id="isNull" name="isNull"  class="area form-control m-b" onchange="selectIsNull(this)">
                    <option value="1">可为空</option>
                    <option value="0">不可为空</option>
                </select>
            </div>
        </div>
        <div class="form-group" id="default">
            <label class="col-sm-3 control-label is-required">默认值：</label>
            <div class="col-sm-8">
                <input  name="default"  class="form-control" type="text" >
                <span class="help-block m-b-none">没有默认值请置空</span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea  name="remark" class="form-control"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: use-js"/>
<script type="text/javascript">
    var prefix = ctx + "db/config";

    function submitHandler() {
        if ($.validate.form() && valiDefault()) {
            $.operate.save(prefix + "/addColumn",$('#form-db-add').serialize());
        }
    }


    /**
     * 选择类型
     */
    function selectOnchange(obj) {
        //DATE没有长度
        if (obj.value == 'DATE'){
            $("#length").hide();
            $("#default").hide();
        } else {
            $("#length").show();
            $("#isNullShow").show();
        }
    }

    /**
     *选择是否可为空
     */
    function selectIsNull(obj) {
        //DATE没有长度
        if (obj.value == 'DATE'){
            $("#length").hide();
        } else {
            $("#length").show();
        }
    }

    /**
     * 默认值不可大于字段长度
     */
    function valiDefault() {
        var length = $('input[name="length"]').val();
        var default_ = $('input[name="default"]').val();
        if ($.common.isNotEmpty(default_) && Number(default_) > Number(length)){
            $.modal.msgError("默认值不可大于字段长度");
            return false;
        } else {
            return true;
        }
    }


</script>
</body>
</html>
